#INCLUDE(${PROJECT_SOURCE_DIR}/cmake/TARGET.cmake)

#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_CFLAGS}")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_CFLAGS}")

SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/output CACHE PATH "Path for libraries")

enable_language(ASM)
set_property(SOURCE head.S PROPERTY LANGUAGE C)

add_library(boot STATIC cpuid.c early.c head.S) 

set(CMAKE_C_FLAGS "${DEBUG_CFLAGS} -m32")

SET_TARGET_PROPERTIES(boot PROPERTIES LINK_FLAGS "-r")

ADD_CUSTOM_TARGET (Brain.bin  ALL)
#ADD_CUSTOM_TARGET (boot Brain.bin)

#SET(LINKBOOT ${CMAKE_C_COMPILER})
SET(LINKBOOT ld)
#SET(LNKFLAGS "\-b binary \-m elf_i386")

add_dependencies( Brain.bin boot )

add_custom_command(TARGET Brain.bin
                   COMMAND pushd ${LIBRARY_OUTPUT_PATH} && ${LINKBOOT} -b binary -m elf_i386 -r -o kernel.o brain && popd
                   COMMAND ${LINKBOOT} -b elf32-i386  -m elf_i386 -T ${CMAKE_SOURCE_DIR}/boot/${ARCH}/boot.ld  -o ${LIBRARY_OUTPUT_PATH}/Brain.bin ${LIBRARY_OUTPUT_PATH}/libboot.a ${LIBRARY_OUTPUT_PATH}/kernel.o
                   COMMENT "Generating Brain.bin")

INCLUDE(CPack)

ENABLE_TESTING()

